package com.ffs.game.scene.obj;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.Animation;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.Actor;

import java.util.HashMap;
import java.util.Map;

/**
 * 地图对象
 *
 * @author ffs80
 */
public abstract class MapObject extends Actor implements IMapObject {

    protected long id;

    /**
     * 行走状态
     */
    protected int walkState;

    /**
     * 站立状态
     */
    protected int standState;

    /**
     * 当前帧
     */
    protected TextureRegion curFrame;

    /**
     * 行走动画
     */
    protected Map<Integer, Animation> walkAnimation = new HashMap<>();

    protected float deltaTime;

    public MapObject(long id, int x, int y, int width, int height) {
        this.id = id;
        this.setX(x);
        this.setY(y);
        this.setWidth(width);
        this.setHeight(height);
    }

    @Override
    public void draw(Batch batch, float parentAlpha) {
        super.draw(batch, parentAlpha);

        deltaTime += Gdx.graphics.getDeltaTime();

        if (curFrame != null) {
            batch.draw(curFrame, getX(), getY(), getWidth(), getHeight());
        }
    }

    @Override
    public long getId() {
        return id;
    }

    /**
     * 步长更新
     */
    public abstract void update(int delta);

    /**
     * 初始化动画
     */
    public abstract void initAnimation();

    public float getDeltaTime() {
        return deltaTime;
    }

    public void setDeltaTime(float deltaTime) {
        this.deltaTime = deltaTime;
    }

    public TextureRegion getCurFrame() {
        return curFrame;
    }

    public void setCurFrame(TextureRegion curFrame) {
        this.curFrame = curFrame;
    }
}
